import * as Blockly from 'blockly/core';

const SENSOR_HUE = 40;  //'#9e77c9'//40;
const ACTUATOR_HUE = 100;
const SERIAL_HUE = 65;

//--------------ASBIT/ESP32部分板载库------------
export const serial_xxbit_image_any = {
    init: function () {
        this.setColour(SERIAL_HUE);
        this.appendDummyInput()
            .appendField("UART1");
        this.appendDummyInput()
            .appendField("有图像传输？");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip();
    }
};

export const serial_xxbit_image_recv = {
    init: function () {
        this.setColour(SERIAL_HUE);
        this.appendDummyInput()
            .appendField("UART1");
        this.appendDummyInput()
            .appendField("获取传输图像");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip();
    }
};

export const serial_xxbit_send = {
    init: function () {
        this.setColour(SERIAL_HUE);
        this.appendDummyInput()
            .appendField("UART2");
        this.appendValueInput('VAR')
            .appendField("发送数据")
            .setCheck("var");
        this.appendDummyInput()
            .appendField("去重")
            .appendField(new Blockly.FieldDropdown([["是", '0'], ["否", '1']]), 'STAT');
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setInputsInline(true);
        this.setTooltip();
    }
};

export const serial_xxbit_recv = {
    init: function () {
        this.setColour(SERIAL_HUE);
        this.appendDummyInput()
            .appendField("UART2");
        this.appendDummyInput()
            .appendField("获取数据");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip();
    }
};

//--------------ACBIT板载库------------
export const sensor_acbit_button_is = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField("获取 按键")
            .appendField(new Blockly.FieldDropdown([
                ["B1", "ob_buttona"],
                ["B2", "ob_buttonb"]
            ]), "TYPE");
        this.appendDummyInput()
            .appendField("被按着");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("[Teaile]:获取板子按键状态");
    }
};

export const sensor_acbit_button_was = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField("获取 按键")
            .appendField(new Blockly.FieldDropdown([
                ["B1", "ob_buttona"],
                ["B2", "ob_buttonb"]
            ]), "TYPE");
        this.appendDummyInput()
            .appendField("被按下");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("[Teaile]:获取板子按键状态");
    }
};

export const serial_asbit_motor = {
    init: function () {
        this.setColour(ACTUATOR_HUE);
        this.appendDummyInput()
            .appendField("Motor");
        this.appendDummyInput()
            .appendField("马达")
            .appendField(new Blockly.FieldDropdown([["M1", 'ob_motor1'], ["M2", 'ob_motor2']]), 'STAT');
        this.appendValueInput('speed')
            .appendField("速度(-100%~100%)")
            .setCheck(Number);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setInputsInline(true);
        this.setTooltip();
    }
};

export const serial_acbit_led = {
    init: function () {
        this.setColour(ACTUATOR_HUE);
        this.appendDummyInput()
            .appendField("LED 指示灯");
        this.appendValueInput('value')
            .appendField("设置亮度")
            .setCheck(Number);
        this.appendDummyInput()
            .appendField("%");
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setInputsInline(true);
        this.setTooltip();
    }
};

export const sensor_acbit_get_brightness = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField("获取");
        this.appendDummyInput()
            .appendField("光线传感器的值(%)");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("[Teaile]:获取板子光线传感器的值 %");
    }
};

export const sensor_xxbit_get_vbat = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput()
            .appendField("获取");
        this.appendDummyInput()
            .appendField("DC端输入电压值(V)");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("[Teaile]:获取板子光线传感器的值 %");
    }
};

//--------------LTBIT板载库------------
export const sensor_ltbit_button_is = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField("获取 按键")
            .appendField(new Blockly.FieldDropdown([
                ["BOOT", "ob_boot"]
            ]), "TYPE");
        this.appendDummyInput()
            .appendField("被按着");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("[Teaile]:获取板子按键状态");
    }
};

export const sensor_ltbit_button_was = {
    init: function () {
        this.setColour(SENSOR_HUE);
        this.appendDummyInput("")
            .appendField("获取 按键")
            .appendField(new Blockly.FieldDropdown([
                ["BOOT", "ob_boot"]
            ]), "TYPE");
        this.appendDummyInput()
            .appendField("被按下");
        this.setInputsInline(true);
        this.setOutput(true, Number);
        this.setTooltip("[Teaile]:获取板子按键状态");
    }
};